<template>
  <div class="app-container customer-div">
      <el-menu :default-active="listQuery.orderState" class="el-menu-demo" mode="horizontal" @select="handleSelect">
          <el-menu-item index="" >全部</el-menu-item>
          <el-menu-item index="0">已成交</el-menu-item>
          <el-menu-item index="50">已完成</el-menu-item>
          <el-menu-item index="10">已取消</el-menu-item>
<!--          <el-menu-item index="deliverAll">交易失败</el-menu-item>-->
<!--          <el-menu-item index="deliverAll">超时取消</el-menu-item>-->
<!--          <el-menu-item index="deliverAll">已逾期</el-menu-item>-->
      </el-menu>

    <div style="margin-top: 40px">
      <!--搜索-->
      <el-form :inline="true" :model="listQuery" size="mini" label-width="100px">
        <el-form-item label="运满满订单号：">
          <el-input v-model="listQuery.ymmOrderId"></el-input>
        </el-form-item>
        <el-form-item label="销售订单号：">
          <el-input v-model="listQuery.orderSn"></el-input>
        </el-form-item>
        <el-form-item label="创建日期：">
          <el-date-picker
                  v-model="listQuery.createTime"
                  type="daterange"
                  format="yyyy 年 MM 月 dd 日"
                  value-format="yyyy-MM-dd"
                  range-separator="至"
                  start-placeholder="开始日期"
                  end-placeholder="结束日期">
          </el-date-picker>
        </el-form-item>
        <el-form-item label="司机信息：" >
          <el-input v-model="listQuery.keywords"></el-input>
        </el-form-item>
<!--        <el-form-item label="协议状态：" >-->
<!--          <el-select value=""></el-select>-->
<!--        </el-form-item>-->
        <el-form-item label="发货人：" >
          <el-select v-model="listQuery.sourceUserId" filterable placeholder="请选择" clearable>
            <el-option
              v-for="item in userOptionList"
              :key="item.userId"
              :label="item.userName"
              :value="item.userId">
            </el-option>
          </el-select>
        </el-form-item>
        <el-form-item label="发货单号：" >
          <el-input v-model="listQuery.deliverSn"></el-input>
        </el-form-item>
        <el-form-item>
          <el-button
                  @click="handleSearchList()"
                  type="primary">
            查询
          </el-button>
        </el-form-item>
      </el-form>
    </div>

    <!--数据列表-->
    <div class="table-container">
      <el-table
              :header-cell-style="{'text-align':'center'}"
              v-loading="listLoading"
              :data="tableData"
              border
              style="width: 100%; margin-top: 20px">
        <el-table-column  label="订单号" min-width="200">
          <template slot-scope="scope">
            <div>
              运满满订单号：<el-link @click="toYmmInfo(scope.row)" type="primary">{{ scope.row.ymmOrderId }}</el-link>
            </div>
            <div>
              销售订单号：<el-link @click="toOrderDetail(scope.row)" type="primary">{{ scope.row.orderSn }}</el-link>
            </div>
            <div>
              发货单号：<el-link @click="toDeliverCon(scope.row)" type="primary">{{ scope.row.deliverSn }}</el-link>
            </div>
          </template>
        </el-table-column>

        <el-table-column  label="出发地-目的地" min-width="150" align="center" >
          <template slot-scope="scope">
              <div>出发地：{{scope.row.sendArea}}</div>
              <div>目的地：{{scope.row.receiveArea}}</div>
          </template>
        </el-table-column>
        <el-table-column  label="承运信息" min-width="150">
          <template slot-scope="scope">
             {{ scope.row.goodsName }} / {{ scope.row.goodsNum }}吨
          </template>
        </el-table-column>
        <el-table-column  label="装卸时间" min-width="150" align="center">
            <template slot-scope="scope">
              <div>装：{{ scope.row.loadTime}}</div>
              <div>卸：{{ scope.row.unloadTime }}</div>
            </template>
        </el-table-column>
        <el-table-column  label="协议费用" min-width="150">
            <template slot-scope="scope">
                <div>总费用：{{ scope.row.freightAmount }}</div>
                <div>定 金：{{ scope.row.deposit }}</div>
<!--                <div>到 付：asdf</div>-->
<!--                <div>回单付：asdf</div>-->
<!--                <div>杂费(装卸费)：asdf</div>-->
            </template>
        </el-table-column>
        <el-table-column  label="司机信息" min-width="150">
            <template slot-scope="scope">
                 <div>司机：{{ scope.row.driverName }}</div>
                 <div>手机：{{ scope.row.driverMobile }}</div>
                 <div>车牌：{{ scope.row.truckNo }}</div>
            </template>
        </el-table-column>
<!--        <el-table-column  label="协议状态" min-width="100" align="center">-->
<!--          <template slot-scope="scope">-->
<!--                已确认-->
<!--          </template>-->
<!--        </el-table-column>-->

<!--        <el-table-column  label="保险信息" min-width="150" align="center">-->
<!--          <template slot-scope="scope">-->
<!--            <div>保额：￥3000</div>-->
<!--            <div>状态：已投保</div>-->
<!--          </template>-->
<!--        </el-table-column>-->

        <el-table-column  label="创建时间" min-width="150" align="center">
          <template slot-scope="scope">
             {{scope.row.createTime}}
          </template>
        </el-table-column>

        <el-table-column  label="操作人" min-width="150">
          <template slot-scope="scope">
<!--             <div>公司名称</div>-->
             <div>发货人：{{ scope.row.createUserName }}  <span>{{ scope.row.createUserMobile }}</span></div>
<!--             <div>录单号：莾顶替 </div>-->
          </template>
        </el-table-column>

        <el-table-column
                width="100"
                fixed="right"
                label="操作"
                align="center">
          <template slot-scope="scope">
                <el-button type="text" size="mini" @click="toYmmInfo(scope.row)">查看</el-button>
          </template>
        </el-table-column>
      </el-table>
    </div>
    <div class="pagination-container">
      <el-pagination
              background
              @size-change="handleSizeChange"
              @current-change="handleCurrentChange"
              layout="total, sizes,prev, pager, next,jumper"
              :current-page.sync="listQuery.pageNum"
              :page-size="listQuery.pageSize"
              :page-sizes="[10,15,20]"
              :total="count">
      </el-pagination>
    </div>


      <!--查看货源-->
      <el-dialog
              :close-on-click-modal="false"
              title="货源信息"
              :visible.sync="dialogVisible"
              width="800px">
          <el-row  :gutter="30">
              <el-col :span="12">
                  <div class="adr-info">
                     <div class="title">装货信息</div>
                     <div class="con">
                        <div class="big-font">江苏常州天宁区</div>
                        <div class="small-font">观城车站(慈溪市育才路与三北中路交汇处) 慈溪市329国道</div>
                        <div class="small-font">装货时间： 2021-05-08 21:00</div>
                     </div>
                  </div>
                  <div class="adr-info yellow" style="margin-top:30px">
                    <div class="title">卸货信息</div>
                    <div class="con">
                      <div class="big-font">江苏常州天宁区</div>
                      <div class="small-font">观城车站(慈溪市育才路与三北中路交汇处) 慈溪市329国道</div>
                      <div class="small-font">卸货时间： 2021-05-08 21:00</div>
                    </div>
                  </div>
              </el-col>
              <el-col :span="12">
                  <el-form>
                     <el-form-item label="车辆信息：" style="margin-bottom:0"></el-form-item>
                     <el-form-item label="货物信息：" style="margin-bottom:0"></el-form-item>
                     <el-form-item label="备注：" style="margin-bottom:0"></el-form-item>
                     <el-form-item label="运费信息：" style="margin-bottom:0"> 20/吨 <span>合计：</span> <span style="color:red">￥ 3800</span></el-form-item>
                     <el-form-item label="订金：" style="margin-bottom:0"></el-form-item>
                     <el-form-item label="开票信息：" style="margin-bottom:0"></el-form-item>
                     <el-form-item label="发布时间：" style="margin-bottom:0"></el-form-item>
                     <el-form-item label="发布人：" style="margin-bottom:0"></el-form-item>
                     <el-form-item label="状态：" style="margin-bottom:0"></el-form-item>
                  </el-form>
              </el-col>
          </el-row>
          <span slot="footer" class="dialog-footer">
              <el-button @click="dialogVisible=false">关 闭</el-button>
              <el-button type="primary" @click="handleConfirm" :loading="btnLoading">下 架</el-button>
          </span>
      </el-dialog>

  </div>
</template>
<script>
  import {getCustomerOption,getOrderUsersList,getDeliverList,deliverUpdate,getQiniuToken,postDeliverVoucher,exportDeliverList,getAddressList} from '@/api/partner'
  import {formatDate} from '@/utils/date';
  import {validateCommission} from '@/utils/validate';

  import store from '@/store'
  import { mapGetters } from 'vuex'
  import {ymmOrderList} from "../../api/partner";
  const defaultListQuery={
    "ymmOrderId":"",  //运满满订单号
    "orderState":"",  //运满满订单状态(0初始状态, 10:已取消,20:已装货,30:已收货,40:已回单,50已完成)
    "orderSn":"",
    "deliverSn":"",
    "createTime":[],
    "keywords":"",
    "sourceUserId":'',
    "pageNum":1,
    "pageSize":10
  };

  export default {
    name: "index",
    data(){
        const isvalidateCommission = (rule, value, callback) => {
            if (!validateCommission(parseFloat(value))) {
                callback(new Error('非负整数或小数'))
            } else if(value > 99999999){
                callback(new Error('最大值为99999999'))
            }else {
                callback()
            }
        };
      return {
        listQuery: JSON.parse(JSON.stringify(defaultListQuery)),
        tableData: [],
        count: 0,
        listLoading: false,
        roles:store.getters.roles ? store.getters.roles : [],
        userOptionList:[],
        dialogVisible:false,
        btnLoading:false,



          diQuIds:[]

      }
    },

    computed: {
      ...mapGetters([
        'name',
        'mobile',
        'userId'
      ]),


    },
    created() {
       this.getAddressListData()
       this.getList();
       this.getUserOptionList();

    },
    filters: {
      formatCreateTime(time) {
        if(time){
          let date = new Date(time);
          return formatDate(date, 'yyyy-MM-dd hh:mm:ss')
        }else{
          return '--'
        }
      },
    },
    methods:{
      //查看发货单
      toDeliverCon(item){
        let routeData = this.$router.resolve({name:'deliverCon',query:{id:item.deliverId,type:'edit'}});
        window.open(routeData.href);
      },

      //查看订单
      toOrderDetail(item){
        let routeData = this.$router.resolve({name:'deliverOrderInfo',query:{id:item.orderId}});
        window.open(routeData.href);
      },
      toYmmInfo(item){
        let routeData = this.$router.resolve({name:'ymmOrderInfo',query:{ymmOrderId:item.ymmOrderId}});
        window.open(routeData.href);
      },
      handleConfirm(item){
        this.$confirm('确认上架此货源吗？', '提示', {
          confirmButtonText: '确定',
          cancelButtonText: '取消',
          type: 'warning'
        }).then(() => {
          this.$message({
            type: 'success',
            message: '删除成功!'
          });
        }).catch(() => {
          this.$message({
            type: 'info',
            message: '已取消删除'
          });
        });
      },
      //获取省市区列表
      getAddressListData(){
        getAddressList().then((res)=>{
          this.options = res;
        })
      },

        showMap(){
          this.$refs.trajectoryMap.showMap();
        },

        //显示货源详情
       showPop(item){
            // this.sendForm = JSON.parse(JSON.stringify(defaultSendForm));
            // this.sendForm.deliverId = item.deliverId;
            this.dialogVisible = true;
        },

        //关闭货源详情
        handleClose(){
            this.dialogVisible = false;

        },


        //查看发货单
        toDetail(item){
            localStorage.setItem('deliverListQuery', JSON.stringify(this.listQuery));
            console.log(item)
            let routeData = this.$router.resolve({name:'deliverCon',query:{id:item.deliverId,type:'edit'}});
            window.open(routeData.href);
        },



      //获取员工下拉选项
      getUserOptionList(){
        getOrderUsersList().then((res)=>{
          this.userOptionList = res;
        })
      },


      /**
       * 切换选择状态
       */
      handleSelect(key, keyPath){
        this.listQuery = JSON.parse(JSON.stringify(defaultListQuery)),
        this.listQuery.orderState = key;
        this.handleSearchList();
      },
      handleSizeChange(val){
        this.listQuery.pageNum = 1;
        this.listQuery.pageSize = val;
        this.getList();
      },
      handleCurrentChange(val){
        this.listQuery.pageNum = val;
        this.getList();
      },

      handleSearchList(){
        this.listQuery.pageNum = 1;
        this.getList();
      },

      //获取发货列表
      getList() {
        this.listLoading = true;
         ymmOrderList(this.listQuery).then(response => {
          this.tableData = response.list;
          this.count = response.count;
          this.listLoading = false;
        }).catch(()=>{
          this.listLoading = false;
        });
      },



    },
  }
</script>

<style lang="scss">
   .adr-info{
      border-radius: 5px;
      border:1px solid #67c23a;
      overflow: hidden;
      background-color: #f0f9eb;
      .title{
        color: #67c23a;
        font-size:14px;
        font-weight: bold;
        text-align: center;
        line-height: 30px;
      }
     .con{
       text-align: left;
       padding:0 10px 10px 10px;
       .big-font{
         font-size:14px;
         color:#333;
         font-weight: bold;
         margin-bottom:10px;
       }
       .small-font{
         font-size:12px;
         color:#333;
         line-height: 20px;
       }
     }
   }
   .adr-info.yellow{
     border:1px solid #e6a23c;
     background-color: #fdf6ec;
     .title{
       color: #e6a23c;
       font-size:14px;
       font-weight: bold;
       text-align: center;
       line-height: 30px;
     }
   }


</style>
